package com.james.customcamera.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.james.customcamera.CustomCameraApplication;
import com.james.customcamera.R;
import com.james.customcamera.bean.PhotoBean;

import java.util.List;

public class LoadMoreWrapperAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<PhotoBean> dataList;

    public LoadMoreWrapperAdapter(List<PhotoBean> dataList) {
        this.dataList = dataList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.home_recycler_item, parent, false);
        return new RecyclerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        RecyclerViewHolder recyclerViewHolder = (RecyclerViewHolder) holder;
        Glide.with(CustomCameraApplication.getContext())
                .load(dataList.get(position).getPictureFileUrl())
                .error(R.mipmap.ic_launcher)
                .into(recyclerViewHolder.imageView);
        recyclerViewHolder.textView.setText(dataList.get(position).getNickname());
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    private class RecyclerViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView textView;

        RecyclerViewHolder(View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.home_recycler_item_image);
            textView = itemView.findViewById(R.id.home_recycler_item_name);
        }
    }

    
}